package com.bbkb.user.util;

import cn.hutool.core.bean.BeanUtil;
import com.bbkb.user.domain.SysMenu;
import com.bbkb.user.domain.SysUser;
import com.bbkb.user.dto.SysMenuDTO;
import com.bbkb.user.dto.SysUserDTO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @作者 沈飞超
 * @功能 转换业务类
 */
public class UserConvert {

    public static SysUser sysUserDto2domain(SysUserDTO source) {
        if (Objects.isNull(source)) {
            return null;
        }
        SysUser target = BeanUtil.copyProperties(source, SysUser.class);
        return target;
    }

    public static SysUserDTO sysUser2Dto(SysUser source) {
        if (Objects.isNull(source)) {
            return null;
        }
        SysUserDTO target = BeanUtil.copyProperties(source, SysUserDTO.class);
        return target;
    }

    public static List<SysUserDTO> sysUser2Dtos(List<SysUser> source) {
        if (Objects.isNull(source)) {
            return null;
        }
        return source.stream().map(UserConvert::sysUser2Dto).collect(Collectors.toList());
    }

    public static SysMenuDTO sysMenu2Dto(SysMenu source) {
        if (Objects.isNull(source)) {
            return null;
        }
        SysMenuDTO target = BeanUtil.copyProperties(source, SysMenuDTO.class);
        return target;
    }

    public static List<SysMenuDTO> sysMenu2Dtos(List<SysMenu> source) {
        if (Objects.isNull(source)) {
            return null;
        }
        return source.stream().map(UserConvert::sysMenu2Dto).collect(Collectors.toList());
    }

}
